package com.ruoyi.eam.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamAsset;
import com.ruoyi.eam.service.IEamAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 固定资产Controller
 *
 * @author ruoyi
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/asset")
public class EamAssetController extends BaseController
{
    @Autowired
    private IEamAssetService eamAssetService;

    /**
     * 查询固定资产列表
     */
    //@RequiresPermissions 这个注解用于指定一个方法或类需要某个特定的权限才能被访问。
    //@RequiresPermissions("system:asset:list")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam Map<String, Objects> map)
    {
        startPage();
        List<EamAsset> list = eamAssetService.selectEamAssetList(map);
        return getDataTable(list);
    }

    /**
     * 导出固定资产列表
     */
//    @RequiresPermissions("system:asset:export")
//    @Log(title = "固定资产", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, EamAsset eamAsset)
//    {
//        List<EamAsset> list = eamAssetService.selectEamAssetList(eamAsset);
//        ExcelUtil<EamAsset> util = new ExcelUtil<EamAsset>(EamAsset.class);
//        util.exportExcel(response, list, "固定资产数据");
//    }



    /**
     * 获取固定资产详细信息
     */
//    @RequiresPermissions("system:asset:query")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(eamAssetService.selectEamAssetByAssetId(assetId));
    }

    /**
     * 新增固定资产
     */
    //@RequiresPermissions("system:asset:add")
    @Log(title = "固定资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.insertEamAsset(eamAsset));
    }

    /**
     * 修改固定资产
     */
//    @RequiresPermissions("system:asset:edit")
//    @Log(title = "固定资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamAsset eamAsset)
    {
        return toAjax(eamAssetService.updateEamAsset(eamAsset));
    }

    /**
     * 删除固定资产
     */
    //@RequiresPermissions("system:asset:remove")
    @Log(title = "固定资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(eamAssetService.deleteEamAssetByAssetIds(assetIds));
    }
}
